package day13.tarena.homework;

import java.util.ArrayList;
import java.util.List;

public class Test {
	private Object[] data;

	private int count;

	List list = new ArrayList();

	public Test() { // 将容量设为10
		data = new Object[10];
	}

	public void add(int index, Object element) {
		if (data[index] == null) {
			data[index] = element;
		} else {
			if (data.length == count) {
				Object[] newArray = new Object[data.length * 2];
				for (int i = 0; i < count; i++) {
					newArray[i] = data[i];
				}
				data = newArray;
			}
			for (int i = count - 1; i > index; i--) {
				data[i + 1] = data[i];
			}
			data[index] = element;
			// System.out.println(data[2]);
		}
		for (int i = 0; i < count; i++) {
			System.out.println(data[i]);
		}
	}

	public static void main(String[] args) {
		Test t = new Test();
		t.add(2, "book");
		t.add(3, "java");
		t.add(0, "one");
		t.add(1, "two");

	}

}
